﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RED_NET_Core.BLL;
using RED_NET_Core.Entity;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;

namespace RED_NET.MasterPage
{
    public partial class Index : System.Web.UI.MasterPage
    {
        protected int uId;
        public String[] Picture, adURLs;
        public string testString = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            testString = "images/c1.jpg";
            if (Session["USER"] != null)//登录好了
            {
                Users user = (Users)Session["USER"];
                uId = user.UserId;
                Label1.Text = "欢迎你，" + user.NickName + "!";
                LinkButton1.Visible = LinkButton2.Visible = true;
                LinkButton3.Visible = false;
            }
            else//未登录
            {
                Label1.Text = "宁大师生欢迎你！";
                LinkButton1.Visible = LinkButton2.Visible = false;
                LinkButton3.Visible = true;
            }
            //动态图处理
            Manager_BLL manager = new Manager_BLL();
            Picture = manager.GetTrendOfManager(1);
            adURLs = manager.GetNewsIdOfTrendImage(1);
            int i = 0;
            while (i < 4)
            {
                adURLs[i] = "~/ContentPage/News/ShowDaily.aspx?VISIT_ID=1&_Id=" + adURLs[i];
                i++;
            }
        }
        public void PopulateNode(Object sender, TreeNodeEventArgs e)
        {
            LoginBLL _login = new LoginBLL();
            DataTable _dt = _login.GetCollegeUser();

            foreach (DataRow _dr in _dt.Rows)
            {
                TreeNode NewNode = new TreeNode(_dr["_NickName"].ToString());
                DataTable _dt2 = _login.GetClassUser(Int32.Parse(_dr["_College"].ToString()));


                // Set additional properties for the node.
                NewNode.SelectAction = TreeNodeSelectAction.Expand;
                TreeNode tNewNode = new TreeNode("学院主页");
                tNewNode.NavigateUrl = "~/ContentPage/User/MainPage.aspx?VISIT_ID=" + _dr["_UId"].ToString();
                tNewNode.SelectAction = TreeNodeSelectAction.Select;
                NewNode.ChildNodes.Add(tNewNode);
                foreach (DataRow _dr2 in _dt2.Rows)
                {

                    NewNode.PopulateOnDemand = true;
                    TreeNode _newNode2 = new TreeNode(_dr2["_NickName"].ToString());
                    _newNode2.PopulateOnDemand = false;
                    _newNode2.SelectAction = TreeNodeSelectAction.Select;
                    _newNode2.NavigateUrl = "~/ContentPage/User/MainPage.aspx?VISIT_ID=" + _dr2["_UId"].ToString();
                    NewNode.ChildNodes.Add(_newNode2);

                }
                // Add the new node to the ChildNodes collection of the parent node.
                e.Node.ChildNodes.Add(NewNode);

            }
            e.Node.CollapseAll();
        }
        protected void TreeView_Navigetion_Selected(object sender, EventArgs e)
        {

        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session["USER"] = null;
            LinkButton1.Visible = LinkButton2.Visible = false;
            LinkButton3.Visible = true;
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            Users user = (Users)Session["USER"];
            Response.Redirect("~/ContentPage/User/MainPage.aspx?VISIT_ID=" + user.UserId.ToString());
        }

        protected void LinkButton3_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ContentPage/Login_2.aspx");
        }
    }
}
